import javax.swing.*;
import java.beans.*;
import java.util.Observer;
import java.util.Observable;
import java.sql.*; 
import java.lang.*;
public class FichaVolumen extends Observable implements Observer {
    
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    
    JFrame ventanaFichaVolumen;
    int codigoMaterial;
   	int codigoVolumen;
   	M_Configuraciones config;
   	M_Volumen volumen;
   	M_Material material;
   	ReservarMaterial reservarMaterial;
    public FichaVolumen(int codVol, int codMat) {
    	codigoMaterial=codMat;
    	codigoVolumen=codVol;
    	volumen = new M_Volumen();
    	config=new M_Configuraciones();
    	config.getDatos();
        levantaVista();
        traerDatos();
        material= new M_Material();
    	material.getDatosMaterial(codigoMaterial);
    	if(material.esPrestable==true && volumen.vol_disponible.equals("PRESTADO")){
    	jButton1.setEnabled(true);	
    	}else{
    		jButton1.setEnabled(false);
    		jButton1.setText("Volumen Disponible");
    	}
    	
    }
    
    
    private void levantaVista() {
    	ventanaFichaVolumen=new JFrame();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();

        ventanaFichaVolumen.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        ventanaFichaVolumen.setTitle("Sistema de administraci\u00f3n.... - Ficha Volumen");
        ventanaFichaVolumen.setResizable(false);
        jLabel1.setFont(new java.awt.Font("Arial", 1, 14));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Ficha Volumen");

        jLabel2.setText("Editorial:");

        jLabel3.setText("Ubicacion:");

        jLabel4.setText("Estado Fisico:");

        jLabel5.setText("CODIGO UNICO:");

        jLabel6.setText("Disponibilidad:");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel7.setText("disponibilidad");

        jLabel8.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel8.setForeground(new java.awt.Color(51, 51, 51));
        jLabel8.setText("00000000");

        jButton1.setText("Reservar este volumen");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Editar datos");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel9.setText("Este volumen esta reservado a:");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel10.setText("Persona");

        jLabel11.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel11.setText("Nota: solo es posible reservar si el volumen esta prestado.");
	ImageIcon volvericon = new ImageIcon("images/left_16x16.gif");
        jButton3.setIcon(volvericon);
        jButton3.setText("Volver");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel12.setText("Ha sido renovado");

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel13.setText("N");

        jLabel14.setText("veces de un maximo de");

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel15.setText("M");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(ventanaFichaVolumen.getContentPane());
        ventanaFichaVolumen.getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 409, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel2)
                    .add(jLabel3)
                    .add(jLabel4)
                    .add(jLabel6)
                    .add(jLabel5)
                    .add(jLabel9))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 114, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(layout.createSequentialGroup()
                        .add(jLabel10)
                        .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel7)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                .add(jTextField3)
                                .add(jTextField2)
                                .add(jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE))
                            .add(jLabel8))
                        .addContainerGap())))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jButton3)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 250, Short.MAX_VALUE)
                .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel11)
                .addContainerGap(149, Short.MAX_VALUE))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jButton1)
                .addContainerGap(287, Short.MAX_VALUE))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel12)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel13)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel14)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel15)
                .addContainerGap(199, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jLabel1)
                .add(21, 21, 21)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(jLabel8))
                .add(28, 28, 28)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jLabel4)
                        .add(16, 16, 16)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel6)
                            .add(jLabel7)))
                    .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel9)
                    .add(jLabel10))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel12)
                    .add(jLabel13)
                    .add(jLabel14)
                    .add(jLabel15))
                .add(7, 7, 7)
                .add(jButton1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel11)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 29, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton3)
                    .add(jButton2))
                .addContainerGap())
        );
        ventanaFichaVolumen.pack();
        ventanaFichaVolumen.setVisible(true);
        jTextField1.setEnabled(false);
        jTextField2.setEnabled(false);
        jTextField3.setEnabled(false); 
    }
//volver
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
	this.setChanged();
	this.notifyObservers(); 
	ventanaFichaVolumen.dispose();
    }
//reservar
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
	ventanaFichaVolumen.setVisible(false);
	reservarMaterial=new ReservarMaterial(codigoVolumen);
	reservarMaterial.addObserver(this);
	
    }
//editar
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    	if(jButton2.getText().equals("Editar datos")){
 		jTextField1.setEnabled(true);
        jTextField2.setEnabled(true);
        jTextField3.setEnabled(true); 
	    jButton2.setText("Guardar cambios");
	    jButton1.setEnabled(false);
	   	System.out.println("editando");
		}else 
		
		if(jButton2.getText().equals("Guardar cambios")){
		editarDatos();
		jTextField1.setEnabled(false);
        jTextField2.setEnabled(false);
        jTextField3.setEnabled(false); 
		jButton2.setText("Editar Datos");
		jButton1.setEnabled(true);
	
		}
    	
    }
    
    private void editarDatos(){
   	
   	volumen.editarDatos(codigoMaterial,codigoVolumen, jTextField1.getText(), jTextField2.getText(), jTextField3.getText());
    }
    
    private void traerDatos(){
    volumen.getDatosVolumen(codigoMaterial, codigoVolumen);
   	volumen.generarIdUnico();
   	jTextField1.setText(volumen.vol_editorial);
   	jTextField2.setText(volumen.vol_ubicacion);
   	jTextField3.setText(volumen.vol_estado_fisico);
   	jLabel8.setText(volumen.idUnico);  //codigo unico
   	jLabel7.setText(volumen.vol_disponible);
   	jLabel10.setText(volumen.vol_reservado_a);
   	jLabel13.setText(volumen.vol_contador_renovaciones_string);
   	jLabel15.setText(Integer.toString(config.renovacionesMax)); //numero maximo
    	
    }
 
    private void reservar(){
    	
    	ReservarMaterial reservarMaterial=new ReservarMaterial(codigoVolumen);
    	
    }
    
    public void update( Observable obse,Object obje ) {
    
    ventanaFichaVolumen.setVisible(true);
    traerDatos();
       
    }
 
 
 
 }
    